import { defineStore } from 'pinia';
import { UserInfo } from '@/types/common/setting.ts';

export const user = defineStore('user', {
  state: (): UserInfo => {
    return {
      username: '',
      nickName: '',
      avatarPath: '',
    };
  },
  getters: {
    userInfo: (state): UserInfo => {
      return {
        username: state.username,
        nickName: state.nickName,
        avatarPath: state.avatarPath,
      };
    },
  },
  actions: {
    updateUser(user: UserInfo) {
      this.$state.username = user.username;
      this.$state.avatarPath = user.avatarPath;
      this.$state.nickName = user.nickName;
    },
  },
  persist: {
    storage: window.localStorage,
  },
});
